/**
 ***********************************************************************************************************
 * 
 ***********************************************************************************************************
 * @file RBHardwareBuffer.h
 ***********************************************************************************************************/

#ifndef __RBHARDWAREBUFFER_H__
#define __RBHARDWAREBUFFER_H__

#ifdef  HEADER_ONCE
#pragma HEADER_ONCE
#endif

#ifdef  HEADER_MSG
#pragma HEADER_MSG(RBHardwareBuffer.h)
#endif

/***********************************************************************************************************
 * Includes
 ***********************************************************************************************************/

#include "RBRefObject.h"
#include "RBRenderer.h"
#include "RBHardwareBufferManager.h"
#include "RBMain/rb_hw_buffer_usage.h"

/***********************************************************************************************************
 * Forward declarations
 ***********************************************************************************************************/

/***********************************************************************************************************
 * Classes
 ***********************************************************************************************************/

using namespace rb_hw_buffer_usage;

class RBHardwareBufferManager;

class RBHardwareBuffer : public RBRefObject
{
    RBDeclareRTTI(RBHardwareBuffer, RBRefObject);
public:

				            RBHardwareBuffer    (uint32 uiUsage, uint32 uiMemPoolMask, RBHardwareBufferManager* pCreator, void* pNative);
    virtual                ~RBHardwareBuffer    ();

    // Function to reset the data: by default, doesn't do anything: only do it on D3D9
    virtual void            OnReset             (bool) {}

    uint32                  GetUsage            () const;

    uint32                  GetMemPool          () const;
    void*                   GetNative           () const;

    virtual bool            Register            (RBStream& kStream);

protected:
    uint32                   m_uiUsage;
    uint32                   m_uiMemPoolMask;
    RBHardwareBufferManager* m_pCreator;
    void*                    m_pNative;
};

RBDeclareSmartPointer(RBHardwareBuffer);

#define RBDeclareHBSerializable(ClassName)                                          \
    static RBHardwareBuffer* CreateObject(RBStream& kStream)                                \
    {                                                                               \
        return RBRenderer::GetSingleton()->GetHBMgr()->Read<ClassName>(kStream);    \
    }/*
                                                                                   \
        virtual void            SerializeRTTI(RBStream& kStream)                        \
        {                                                                               \
            kStream.WriteRTTI(ClassName::GetStaticRTTI(), this);                        \
            m_pCreator->Write(this, kStream);                                           \
        }*/
    



/***********************************************************************************************************/

/***********************************************************************************************************
 * 
 ***********************************************************************************************************/
inline uint32 RBHardwareBuffer::GetUsage() const
{
    return m_uiUsage;
}



/***********************************************************************************************************
 * 
 ***********************************************************************************************************/
inline uint32 RBHardwareBuffer::GetMemPool() const
{
    return m_uiMemPoolMask;
}

#endif // __RBHARDWAREBUFFER_H__